Component({
  data: {
    selected: 0
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      this.setData({
        selected: data.index
      })
      wx.switchTab({
        url
      })
    },
    publish() {
      wx.navigateTo({
        url: '/pages/publish/publish'
      })
    }
  },
  pageLifetimes: {
    show() {
      const pages = getCurrentPages()
      const currentPage = pages[pages.length - 1]
      const route = currentPage.route

      let selected = 0
      if (route.includes('index')) selected = 0
      else if (route.includes('ayi')) selected = 1
      else if (route.includes('message')) selected = 3
      else if (route.includes('my')) selected = 4

      this.setData({ selected })
    }
  }
}) 